package com.example.iot.queue.inMemory;

import com.example.iot.queue.QueueConsumer;
import com.example.iot.queue.QueueFactory;
import com.example.iot.queue.QueueProducer;
import com.example.iot.queue.configuration.RuleEngineQueueConfig;
import com.example.iot.queue.message.RuleEngineQueueMsg;
import com.example.iot.queue.message.ProtoQueueMsg;
import com.example.iot.queue.rabbitMq.TbRabbitMqAdmin;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.stereotype.Component;

import javax.annotation.PreDestroy;

/**
 * @author ChenXiangpeng
 */
@Slf4j
@Component
@ConditionalOnExpression("'${queue.type:null}'=='in-memory'")
public class InMemoryQueueFactory implements QueueFactory {

    private final RuleEngineQueueConfig ruleEngineQueueConfig;

    public InMemoryQueueFactory(RuleEngineQueueConfig ruleEngineQueueConfig) {
        this.ruleEngineQueueConfig = ruleEngineQueueConfig;
    }

    @Override
    public QueueProducer<ProtoQueueMsg<RuleEngineQueueMsg>> createRuleEngineProducer() {
        return new InMemoryQueueProducer<>(ruleEngineQueueConfig.getTopic());
    }

    @Override
    public QueueConsumer<ProtoQueueMsg<RuleEngineQueueMsg>> createRuleEngineConsumer() {
        return new InMemoryQueueConsumer<>(ruleEngineQueueConfig.getTopic());
    }
}
